import sys


class Solution():
    def happy_number(self, n: str) -> int:
        if len(n) < 1:
            return -1

        mul = 1
        while(True):
            temp_n = mul * int(n)
            num_dic = self.get_num_dic(str(temp_n))
            if len(num_dic) <= 3:
                flag = 1
                for key, value in num_dic.items():
                    if key != '0' and key != '1':
                        flag -= 1
                if flag >= 0:
                    return temp_n
            mul += 1

    def get_num_dic(self, s: str):
        num_dic = {}
        for i in range(len(s)):
            if s[i] not in num_dic:
                num_dic[s[i]] = 1
            else:
                num_dic[s[i]] += 1
        return num_dic


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    x = Solution()
    print(x.happy_number(str(n)))